import { Inject, Provide } from '@midwayjs/decorator';
import { BaseService} from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BroadcastRecipeEntity } from '../entity/recipe';
import { Context } from '@midwayjs/koa';

/**
 * 象数配方
 */
@Provide()
export class BroadcastRecipeService extends BaseService {
  
  @InjectEntityModel(BroadcastRecipeEntity)
  BroadcastRecipeEntity: Repository<BroadcastRecipeEntity>;

  @Inject()
  ctx: Context;

  /**
   * 获取id或parentId的数据
   * @param id
   */
  async getRecipeOrParent(id) {
    let recipeInfo=await BroadcastRecipeEntity.findOneBy({id})
    let recipeList=await BroadcastRecipeEntity.findBy({parentId:id})
    recipeInfo.children=recipeList
    return recipeInfo
  }
}
